home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0054_Dos Prompt.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  4KB  |  70 lines

  1.  
  2. {
  3.  There are 2 ways that I can think of off hand. One is to execute
  4.  COMMAND.COM with the parameter '/K PROMPT [Whatever]' OR You could
  5.  create your own program enviroment and then add/edit as many enviroment
  6.  variables as you have memory for. The following program demonstrates
  7.  this. It creates its own enviroment , then copies the old info to it
  8.  but changes the prompt to whatever you want. After the shell it
  9.  releases the memory:
  10. }
  11.  
  12. {***********************************************************************}
  13. PROGRAM PromptDemo;             { Apr 18/94, Greg Estabrooks.           }
  14. {$M 16840,0,0}                  { Reserved some memory for the shell.   }
  15. USES CRT,                         { IMPORT Clrscr,Writeln.              }
  16.      DOS;                         { IMPORT Exec.                        }
  17.  
  18. PROCEDURE ShellWithPrompt( Prompt :STRING );
  19.                          { Routine to allocate a temporary Enviroment   }
  20.                          { with our prompt and the execute COMMAND.COM. }
  21.                          { NOTE: This does NO error checking.           }
  22. VAR
  23.    NewEnv :WORD;                { Points to our newly allocated env.    }
  24.    OldEnv :WORD;                { Holds Old Env Segment.                }
  25.    EnvPos :WORD;                { Position inside our enviroment.       }
  26.    EnvLp  :WORD;                { Variable to loop through ENVStrings.  }
  27.    TempStr:STRING;              { Holds temporary EnvString info.       }
  28. BEGIN
  29.   ASM
  30.    Mov AH,$48                   { Routine to allocate memory.           }
  31.    Mov BX,1024                  { Allocate 1024(1k) of memory.          }
  32.    Int $21                      { Call DOS to allocate memory.          }
  33.    Mov NewEnv,AX                { Save segment address of our memory.   }
  34.   END;
  35.  
  36.   EnvPos := 0;                  { Initiate pos within our Env.          }
  37.   FOR EnvLp := 1 TO EnvCount DO { Loop through entire enviroment.       }
  38.    BEGIN
  39.     TempStr := EnvStr(EnvLp);   { Retrieve Envirment string.            }
  40.     IF Pos('PROMPT=',TempStr) <> 0 THEN  { If its our prompt THEN ....  }
  41.      TempStr := 'PROMPT='+Prompt+#0  { Create our new prompt.           }
  42.     ELSE                        {  .... otherwise.........              }
  43.      TempStr := TempStr + #0;   { Add NUL to make it ASCIIZ compatible. }
  44.     Move(TempStr[1],Mem[NewEnv:EnvPos],Length(TempStr)); { Put in Env.  }
  45.     INC(EnvPos,Length(TempStr)); { Point to new position in Enviroment. }
  46.    END;{For}
  47.  
  48.   OldEnv := MemW[PrefixSeg:$2C];{ Save old enviroment segment.          }
  49.   MemW[PrefixSeg:$2C] := NewEnv;{ Point to our new enviroment.          }
  50.   SwapVectors;                  { Swap Int vectors in case of conflicts.}
  51.   Exec(GetEnv('COMSPEC'),'');   { Call COMMAND.COM.                     }
  52.   SwapVectors;                  { Swap em back.                         }
  53.   MemW[PrefixSeg:$2C] := OldEnv;{ Point back to old enviroment.         }
  54.  
  55.   ASM
  56.    Push ES                      { Save ES.                              }
  57.    Mov AH,$49                   { Routine to deallocate memory.         }
  58.    Mov ES,NewEnv                { Point ES to area to deallocate.       }
  59.    Int $21;                     { Call DOS to free memory.              }
  60.    Pop ES                       { Restore ES.                           }
  61.   END;
  62. END;{ShellWithPrompt}
  63.  
  64. BEGIN
  65.   Clrscr;                        { Clear the screen.                    }
  66.   Writeln('Type EXIT to return');{ Show message on how to exit shell.   }
  67.   ShellWithPrompt('[PromptDemo] $P$G'); { shell to DOS with our prompt. }
  68. END.{PromptDemo}
  69. {***********************************************************************}
  70.